



export type StartChatFnProps = {
    messages: ChatCompletionUserMessageParam[];
    responseChatItemId?: string;
    controller: AbortController;
    variables: Record<string, string | number | boolean>;
    generatingMessage: (e: generatingMessageProps) => void;
  };
  
  export interface ChatCompletionUserMessageParam {
    /**
     * The contents of the user message.
     */
    content: string | Array<ChatCompletionContentPart>; 
  
    /**
     * The role of the messages author, in this case `user`.
     */
    role: 'user';
  
    /**
     * An optional name for the participant. Provides the model information to
     * differentiate between participants of the same role.
     */
    name?: string;
  }
  
  export type ChatCompletionContentPart = ChatCompletionContentPartText | ChatCompletionContentPartImage;
  
  export interface ChatCompletionContentPartText {
    /**
     * The text content.
     */
    text: string;
  
    /**
     * The type of the content part.
     */
    type: 'text';
  }
  
  
  export interface ChatCompletionContentPartImage {
    image_url: ImageURL;
  
    /**
     * The type of the content part.
     */
    type: 'image_url';
  }
  
  
  export interface ImageURL {
    /**
     * Either a URL of the image or the base64 encoded image data.
     */
    url: string;
  
    /**
     * Specifies the detail level of the image. Learn more in the
     * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).
     */
    detail?: 'auto' | 'low' | 'high';
  }
  
  
  export type generatingMessageProps = {
    event: SseResponseEventEnum;
    text?: string;
    reasoningText?: string;
    name?: string;
    status?: 'running' | 'finish';
    tool?: unknown;
    variables?: Record<string, string | number | boolean>;
    isAnswerDone?: boolean;
    nodeResponse?: unknown;
    [key: string]: unknown;
  };
  
  export enum SseResponseEventEnum {
    error = 'error',
    answer = 'answer', // animation stream
    fastAnswer = 'fastAnswer', // direct answer text, not animation
    flowNodeStatus = 'flowNodeStatus', // update node status

    answerDone = 'answerDone', // answer done
    toolCall = 'toolCall', // tool start
    toolParams = 'toolParams', // tool params return
    toolResponse = 'toolResponse', // tool response return
    flowResponses = 'flowResponses', // sse response request
    updateVariables = 'updateVariables',
    interactive = 'interactive',
    flowNodeResponse = 'flowNodeResponse',
    workflowDuration = 'workflowDuration'
  }

  // 聊天消息接口
  export interface ChatMessage {
    id: string;
    content: string;
    role: 'user' | 'assistant' | 'system';
    timestamp: Date;
    isGenerating?: boolean;
  }

  // 聊天请求参数
  export interface ChatRequestParams {
    chatId?: string;
    messages: Array<{
      role: 'user' | 'assistant' | 'system';
      content: string;
    }>;
    stream?: boolean;
    detail?: boolean;
    variables?: Record<string, string | number | boolean>;
    contentId?: string;
  }

  // 聊天响应
  export interface ChatResponse {
    id: string;
    model: string;
    usage: {
      prompt_tokens: number;
      completion_tokens: number;
      total_tokens: number;
    };
    choices: Array<{
      message: {
        role: string;
        content: string;
      };
      finish_reason: string;
      index: number;
    }>;
    chatId?: string;
  }
  